/**
 * 
 */
package com.shine.icis.hbean;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.apache.struts2.json.annotations.JSON;


/**
 * 流程实例
 * @author zsy
 *
 */
public class FlowIns implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1998411859294309098L;
	private String insId;
	private String insName;//实例名称
	private Date createTime;//创建时间
	private Date endTime;//结束时间
	
	private FlowDef flowDef;//审批流程
	private FlowNode flowNode;//当前步骤
	private Set<TaskIns> taskInses;//任务实例
	private Map<String, FlowVar> flowVars;//上下文变量
	public String getInsId() {
		return insId;
	}
	public void setInsId(String insId) {
		this.insId = insId;
	}
	public String getInsName() {
		return insName;
	}
	public void setInsName(String insName) {
		this.insName = insName;
	}
	
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public Date getEndTime() {
		return endTime;
	}
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	@JSON(serialize=false)
	public FlowDef getFlowDef() {
		return flowDef;
	}
	public void setFlowDef(FlowDef flowDef) {
		this.flowDef = flowDef;
	}
	@JSON(serialize=false)
	public FlowNode getFlowNode() {
		return flowNode;
	}
	public void setFlowNode(FlowNode flowNode) {
		this.flowNode = flowNode;
	}
	@JSON(serialize=false)
	public Set<TaskIns> getTaskInses() {
		return taskInses;
	}
	public void setTaskInses(Set<TaskIns> taskInses) {
		this.taskInses = taskInses;
	}
	
	@JSON(serialize=false)
	public Map<String, FlowVar> getFlowVars() {
		return flowVars;
	}
	
	public void setFlowVars(Map<String, FlowVar> flowVars) {
		this.flowVars = flowVars;
	}
	
	/**
	 * 添加变量
	 * @param var
	 */
	public void addFlowVar(FlowVar var) {
		if (flowVars == null) {
			flowVars = new HashMap<String, FlowVar>();
		}
		flowVars.put(var.getVarName(), var);
	}
	
	/**
	 * 取得变量
	 * @param name
	 * @return
	 */
	public FlowVar getFlowVar(String name) {
		if (flowVars == null) {
			return null;
		}
		return flowVars.get(name);
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((insId == null) ? 0 : insId.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final FlowIns other = (FlowIns) obj;
		if (insId == null) {
//			if (other.insId != null)
				return false;
		} else if (!insId.equals(other.insId))
			return false;
		return true;
	}

}

